Repository navigation
fix(pc-mate): deliver Feishu replies visibly and accept flattened mentions - #2981
AlexStocks wants to merge 9 commits into
Conversation
…tions Three defects kept the Feishu group channel silent even though the event arrived and the model produced a verdict. 1. A flattened event has no `mentions` array, so a group message that explicitly addressed the bot was dropped by `parse_event` and the run ended silently. `feishu.botName` now lets the rendered text carry the address when the structured array is absent. An unaddressed group message is still rejected, so RFC 2919 L92 full group ingestion stays excluded. 2. The reply body was passed through shortcut flags such as `--markdown -`, which are not stdin markers: the literal dash was published as the answer. The body is now built as JSON and delivered on stdin to `lark-cli api POST ... --data -`, so untrusted model output never becomes an argv value either. 3. The reply carried `reply_in_thread=true`, which hides it in a side thread. Users saw nothing in the chat and reported that the bot had not answered. Group replies now land in the chat timeline.
The controller now separates triage from code execution. An accepted bug/feature gets its own Git worktree under stateDir/work/<case> and a branch off the configured base, and the agent runs there with write access. The shared checkout stays read-only for the whole pipeline, the controller commits the result and saves a binary patch, and the branch stays local until a person publishes it. The manual run command follows the same rule: --write now works in a one-off worktree instead of the shared checkout. Cleanup is explicit and refuses any path outside this installation's work directory.
hidb4ai
left a comment
There was a problem hiding this comment.
Two reproduced correctness issues in the new group-address fallback and worktree recovery path are detailed inline.
| && !config.bot_name.trim().is_empty() | ||
| && raw | ||
| .to_ascii_lowercase() | ||
| .contains(&format!("@{}", config.bot_name.trim().to_ascii_lowercase())); |
There was a problem hiding this comment.
[P2] Restrict the display-name fallback to an exact bot mention without authoritative mention metadata. With botName=ClawBot, parse_event accepts an allowed-group message addressed to @ClawBotHelper. It also accepts @clawbot when the supplied structured mention explicitly identifies ou_other rather than the configured bot. Both cases return a trigger in a public parse_event reproduction, admitting messages that were not addressed to this bot into triage. Only use the fallback when structured identity is unavailable, and require an exact mention boundary.
| ) -> Result<RemoveOutcome> { | ||
| let record = | ||
| load(state_dir, case_id)?.with_context(|| format!("no worktree record for {case_id}"))?; | ||
| let directory = std::fs::canonicalize(&record.directory) |
There was a problem hiding this comment.
[P2] Allow cleanup of a record whose worktree directory is already missing. After prepare creates a worktree, deleting that directory makes the next prepare instruct the operator to run pc-mate worktree remove CASE. That command fails here during canonicalize and leaves the record intact, so the documented recovery cannot unblock the case. Reproduced with a real temporary Git repository through prepare/remove/load. Handle the missing-directory case while retaining path containment checks and pruning the stale Git registration, so the case can be prepared again.
The supervisor-agent architecture needs a domain that can say what a message was, what it authorised, and who may still decide it. That vocabulary comes from smallnest/superagent, so the core is ported rather than reinvented: - Trigger, Thread, Evaluation, Decision, Mandate, Ticket, Assignment and the invariants between them (core/model.rs). - Intake, evaluations, tickets, assignments and replies as one engine, with every mutation behind a port so the domain runs in memory in a test and on disk in the service (core/ports.rs, core/engine.rs). - The two strengths of authorisation, explicit and inferred, and the rule that an inferred mandate may only write when its assessment says the work is an implementation. pc-mate's own four-way intent analysis travels with the ticket it accepts, so the first step of the pipeline stays what it was.
…cket Port the superagent domain core (model, engine, intake, evaluations, tickets, assignments, replies, reasons, ports) and drive it from a supervisor that decides what should happen while the agent does it. The first step of the assessment stays pc-mate's own four-way intent analysis. Everything after it follows superagent: consecutive messages of one thread are assessed together after a quiet period, the assessment produces a mandate, and the mandate decides what the worker may do. The agent runs in a Git worktree of its own. A run that asks a question keeps its worktree and waits for the answer; the answer reaches the next run's prompt. The write stage reports in .pc-mate/outcome.json, the read stage answers in prose. The controller commits the result and ends the worktree in a fixed order: save the patch, push the branch, remove the worktree, delete the local branch. Settings: supervisor.enabled, supervisor.batchWindowSeconds (45), executor.push.
|
codex seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
The affected modules are pc-mate. @hidb4ai, please coordinate follow-up. pc-mate: @hidb4ai @AlexStocks. Please coordinate the review of the affected changes. |
The README now carries a Mermaid diagram of the supervisor, the worktree write stage, PowerContext evidence and memory, and the approval path. It also follows the memory move: the lesson is written before cleanup, outcome.json never reaches the branch, and followupAfterSeconds starts from the pushed branch. The verification note records the local Linux and Windows results.
Which issue or RFC does this PR close?
Closes #.
Related discussion: #2970
Worktree architecture: #2922
Rationale for this change
The Feishu group channel produced no visible answer even though the event was
delivered and the model returned a verdict. Three separate defects were
involved, each hiding the response at a different stage.
1. A flattened event was dropped before triage. The configured event
transport (
lark-cli event consume) emits a flattened callback that carries nostructured
mentionsarray.parse_eventrequired a mention whose id matchedbot_id/app_id, so a group message that explicitly addressed the bot byname was rejected and the run ended without a trace.
feishu.botNamenowcarries the display name, and the rendered text is used to recognise an
explicit
@<botName>address when the structured array is absent. Anunaddressed group message is still rejected, so the RFC 2919 L92 exclusion of
full group ingestion is unchanged.
2. The reply body was published as a literal dash. The body was passed to
shortcut flags such as
--markdown -, which are not stdin markers: the CLIpublished the
-as the answer. The body is now built as JSON and deliveredon stdin to
lark-cli api POST ... --data -. This also keeps untrusted modeloutput out of argv, which the previous shortcut form already intended.
3. The reply was hidden in a side thread. The reply carried
reply_in_thread=true, so it appeared only under the thread view and not inthe chat timeline. From the group's point of view the bot had not answered.
Group replies now land in the chat timeline.
4. The pipeline could not finish a programming task. Triage and the
implementation proposal both ran read-only in the shared checkout, so an
accepted report ended as a plan in the chat: the agent could read the
repository but could not change anything, and it had no directory of its own
to change. Discussion #2922 asks for the supervisor/agent split to stay, with
triage and code execution separated and every implementation task running in
its own Git worktree. The controller now creates that worktree
(
stateDir/work/<case>) with a branch off the configured base, runs the agentthere with write access, commits the result, and saves the patch. The shared
checkout stays read-only for the whole pipeline. The branch is pushed to
git.remotebefore the worktree is removed, so the work is on the remotebefore the only copy of it goes away; opening a pull request and merging stay
with a person.
5. The loop had no supervisor. A message was triaged, answered and
implemented by one linear pipeline. That pipeline had no notion of an
authorization that travels with the work, no way to hold a question open until
the requester answers it, and no way to read a burst of messages about one
problem as one problem. Discussion #2922 asks for the supervisor/agent split,
and the supervisor-agent architecture of
smallnest/superagentis the shapethe loop now has: the supervisor decides what should happen, the agent does
it, and the authorization that travels between them is a mandate.
What changes are included in this PR?
pc-mate/src/config.rs: newfeishu.botNamefield, defaulting to empty.pc-mate/src/sources/feishu.rs:parse_eventaccepts a group message addressed by the configured displayname when the event carries no structured mention, and strips that prefix
from the command text.
reply_args/chat_argsuse the genericapi POSTform with--data -;reply_body/chat_bodybuild the JSON payload.reply_in_threadis no longer set, so a group reply is visible in thechat itself.
pc-mate/settings.example.yaml: documentsbotName.pc-mate/README.md: documentsfeishu.botNameand when it is needed.pc-mate/docs/rfc-conformance.md: two new rows — a flattened group eventstill requires an explicit address, and a reply body reaches Feishu verbatim
and lands in the chat timeline.
flattened_group_event_with_display_name_only_is_accepted;reply_payloads_are_read_from_stdin_not_argvupdated for the new argumentshape.
The worktree stage adds:
pc-mate/src/worktree.rs(new): the per-case worktree lifecycle. It createsthe worktree and branch, commits the agent's work with a fixed identity,
saves
stateDir/cases/<case>/worktree.patch, records branch/base/head instateDir/cases/<case>/worktree.json, and removes a worktree only aftersaving what only it holds. A recorded path outside this installation's
stateDir/workis refused, so the shared checkout is never a cleanuptarget.
pc-mate/src/workflow.rs: the implementation stage. The accepted report isanalysed read-only as before, then the agent runs with write access in the
case's worktree. The controller commits the result; the reply names the
branch, the commit and the changed files, and states that nothing was
pushed.
pc-mate/src/config.rs: theexecutorsection (enabled,branchPrefix).The branch prefix is validated against the rules git applies to a branch
name, and an unattended implementation refuses OpenCode, which cannot
confine its writes.
pc-mate/src/app.rs:run_agent_in_worktree.pc-mate run --writenowwrites in a one-off worktree too, so no agent writes the shared checkout.
pc-mate/src/cli.rs:pc-mate worktree listandpc-mate worktree remove <case-id>, and adoctorcheck that the checkoutcan host case worktrees.
pc-mate/README.mdandpc-mate/docs/rfc-conformance.md: the worktreelifecycle, the enforced invariants and the remaining gaps.
two_cases_get_distinct_worktrees_and_the_shared_checkout_stays_clean,the_controller_commits_the_agent_work_and_saves_the_patch,cleanup_saves_uncommitted_work_before_removing_the_worktree,cleanup_refuses_a_recorded_path_outside_the_installation_work_directory,an_accepted_task_is_implemented_inside_its_own_worktree,a_disabled_executor_stops_after_the_read_only_proposal,an_implementation_reply_names_the_branch_and_claims_no_publication,a_branch_prefix_that_git_would_refuse_is_rejected_at_load_time,an_unattended_implementation_refuses_a_runner_that_cannot_confine_its_writes.The supervisor stage adds:
pc-mate/src/core/(new): the domain core, ported fromsmallnest/superagent'ssrc/core/.model.rs(ticket, thread, decision,mandate, assignment, worker report),
ctx.rs,engine.rs,intake.rs,evals.rs,tickets.rs,assignments.rs,replies.rs,reasons.rs,errors.rs,ids.rs, and theportsthe domain talks to.pc-mate/src/supervisor/(new): the ports' pc-mate implementations.policy.rsis the mandate policy — a listed person who addressed the agentmakes an explicit request, everything else worth assessing is inferred,
and an inferred authorization may only implement under
triage.mode: auto.assessor.rsholds the batches that wait for the quiet period,executor.rsholds the assignments that wait to run,
outbox.rsholds the replies thatwait to go out,
repository.rsis the durable state, andscope.rssayswhich sources are read.
pc-mate/src/outcome.rs(new): the report of the write stage. The read stageanswers in prose; the write stage writes
.pc-mate/outcome.json— thesummary, the state, the files it changed, the commands it ran, the question
it still has, the lesson it learned and
followupAfterSeconds. The file isnamed
outcome.jsonand notreport.json, because the read stage's answeris the report and the two are not interchangeable.
pc-mate/src/app.rs: the pipeline is nowsupervisor.receive→supervisor.tick→ deliver. The worker runs in a background task, so along implementation does not stop the bot from taking messages in. The
GitHub write path is unchanged: a reply still becomes a pending action that
waits for the approval.
pc-mate/src/supervisor/mod.rs: the assessment keeps the memory the earlierpipeline had. Every batch is assessed against the public Scope through
POST /v1/context/prepareagain, and an empty or failed read is passed tothe model as evidence absence instead of being guessed around. The read-only
answer prompt carries the keynotes summary again, as the earlier proposal
prompt did.
pc-mate/src/config.rs: thesupervisorsection (enabled,batchWindowSeconds, default 45) andexecutor.push(defaulttrue).pc-mate/src/worktree.rs:cleanupends a worktree in a fixed order —save the patch, push the branch, remove the worktree, delete the local
branch — and a failure anywhere above leaves the worktree and the branch in
place. A worktree whose run stopped to ask a question is kept, and a
re-check continues the branch the installation pushed before.
pc-mate/README.mdandpc-mate/docs/rfc-conformance.md: the supervisorarchitecture, the mandate rules, the report protocol, the worktree
lifecycle and the remaining gaps.
an_accepted_request_creates_a_ticket_that_owns_its_thread,a_listed_person_who_names_the_agent_makes_an_explicit_request,a_remark_from_a_listed_person_is_only_an_inferred_candidate,only_the_auto_mode_accepts_an_inferred_candidate,consecutive_messages_are_assessed_together,a_disabled_executor_stops_after_the_read_only_stage,a_ticket_that_asks_to_look_again_is_checked_again,a_question_waits_for_the_answer_and_the_work_continues,an_outcome_names_what_was_done_and_how_it_was_checked,a_file_that_is_not_an_outcome_is_refused,a_run_that_wrote_nothing_falls_back_to_its_own_words,a_failed_assessment_answers_nobody,a_category_outside_the_configured_set_has_no_side_effects,a_message_that_was_taken_in_is_not_answered_twice,a_reply_that_could_not_be_delivered_is_tried_again,prepared_evidence_reaches_the_prompt_verbatim,an_empty_prepared_context_is_declared_insufficient.No persisted format, public API, or approval boundary changes. The write
boundary, the read-only agent contract and the PowerContext access rules are
untouched.
Are there any user-facing changes?
Yes. A group reply now appears in the chat timeline instead of in a side
thread, and a message that addresses the bot by name is answered even when the
event source drops the structured mention array.
feishu.botNameis a new optional setting. It defaults to empty, so anexisting installation behaves exactly as before until it is set.
The worktree stage adds two optional settings,
executor.enabled(defaulttrue) andexecutor.branchPrefix(defaultpc-mate/), plusgit.baseBranchfor the commit a worktree branches from (nullkeeps thecheckout's current HEAD). The implementation stage is reached only in
triage.mode: auto;observeandreplybehave as before, andexecutor.enabled: falsekeeps the old proposal-only behaviour.The implementation stage changes code in a worktree of its own and pushes that
branch to
git.remote: no pull request, no merge. A ticket that wasimplemented carries the new
implementedticket state.The supervisor stage adds three optional settings:
supervisor.enabled(default
true),supervisor.batchWindowSeconds(default45, the quietperiod before one thread's queued messages are assessed together) and
executor.push(defaulttrue, whether the branch is pushed before theworktree is removed).
proposal.enabledandtriage.autoLabelare kept so anexisting settings file still loads; the supervisor replaced the pipeline that
read them, so they no longer have an effect, and both are documented as such.
The answer to a question now waits for the requester: a run that asks one
keeps its worktree, the question goes to the conversation, the answer is put
in the prompt of the next run, and the work continues in the same directory.
How was this change tested?
Commands run:
fmtandclippypass. On this Windows hostcargo test --lockedreports157 passed and 1 failed:
sources::github::tests::polling_a_changed_issue_keeps_unseen_human_comments_across_pages.That failure is not caused by this change — it reproduces identically on
the unmodified
mastertree at5d55eeb7with the sametcp connect error (os error 10060)against its loopback mock server. It is apre-existing local-environment failure in
github.rs, which this PR does nottouch.
On the earlier head
efd37dc8, the same suite on Linux, with the pinnedtoolchain and the same loopback behaviour CI has, passes completely:
cargo fmt --all --checkandcargo clippy --locked --all-targets -- -D warningsalso pass on Linux with Rust 1.95.0, the version CI pins.
Manual validation on this host, against a real Feishu group:
@ClawBot …message was received by the event bus(
RECEIVED=1 / DROPPED=0) but produced notriage/record and no reply.replied: trueand areply_id, and the reply body was delivered into thechat with its full text.
Not verified in this environment: a real GitHub App installation token, real
GitHub issue/comment/label writes, real PowerContext Scope/Principal
enforcement, and the
im.message.recalled_v1event handling that the eventtransport also emits.
The worktree stage has not run against a real model yet: the lifecycle is
covered by tests that drive the controller, but no real agent diff has been
produced on this host. The controller does not re-run the tests the agent
reports, so a test result in an implementation reply is the agent's claim and
is labelled as such.
The supervisor stage was verified on this host at head
8ce892bc2:fmt --checkandclippy -D warningspass.cargo test --lockedreports184 passed, 1 failed:
sources::github::tests::polling_a_changed_issue_keeps_unseen_human_comments_across_pages.That failure is not caused by this change — it was reproduced on the
unmodified merge base of this branch (
5d55eeb7f, i.e.masterat the timeof the branch point) with the same
tcp connect error (os error 10060)againstits loopback mock server. It is a pre-existing local-environment failure in
github.rs, which this PR does not touch.The same suite on Linux, with the pinned toolchain and the loopback behaviour
CI has, passes completely:
GitHub CI at head
8ce892bc2: thePC-Mateworkflow was dispatched by handwith
gh workflow run pc-mate.yml --ref feat/pc-mate-feishu-reply-fixes. Run47072966860
(
workflow_dispatch, head8ce892bc2) succeeds:changes / detectand thecheckjob (format check, lint, test, build) both pass.The PR's
Mainorchestrator cannot go green at this head for a reason outsidethis change:
CI preflightfails inuv lock --project e2e/bub --locked("The lockfile at
uv.lockneeds to be updated"), andmasteritself failsthe same step at
1a34cdc53(run47064599887,
job
CI preflight). The pc-mate jobs are skipped because that preflight fails,not because pc-mate failed.
license/claremains pending, so the PR staysBLOCKED.The supervisor's own behaviour is covered by tests that drive the controller
end to end: a task is implemented inside its own worktree and the branch
reaches the remote; the shared checkout stays clean; consecutive messages are
assessed together; a ticket that asks to look at itself again is checked
again; a question waits for the requester's answer and the work then continues
in the same worktree; a message is not answered twice; a reply that could not
be delivered is tried again.
Not verified in this environment: a push against a remote that needs
credentials (the tests push to a local bare repository), a real model run
that produces a real diff, and the agent asking a question against a live
Feishu group.
AI usage statement
This change was produced with AI assistance (Claude, via WorkBuddy). The
analysis of the three failure stages, the patch, the unit tests and the
manual Feishu validation were all carried out with AI support; the commit
message and this description were written from that work.
The worktree stage was produced with AI assistance as well (OpenAI Codex, with
the MiniMax-M3.1 model). The design followed Discussion #2922 and the
worktree lifecycle of
smallnest/superagent; the Rust implementation, thetests, the documentation and this description were written with that
assistance.
The supervisor stage was produced with AI assistance as well (OpenAI Codex).
The domain core is a port of
smallnest/superagent'ssrc/core/; themandate policy, the worktree lifecycle, the report protocol, the quiet
period and the self-review were implemented against Discussion #2922 and the
maintainer's decisions on this PR. The Rust implementation, the tests, the
documentation and this description were written with that assistance.