Skip to content

investigate: answer command for AI sessions, parent_run on starts - #486

Merged
maximelb merged 3 commits into
masterfrom
ia-ca-answer-cli
Nov 27, 2026
Merged

maximelb merged 3 commits into
masterfrom
ia-ca-answer-cli

Conversation

@maximelb

Copy link
Copy Markdown
Contributor

What

The command an Investigation Engine AI session uses to answer the ai_agent step that started it, and the loop guard on starts the session makes.

  • limacharlie investigate answer (--answer JSON | --answer-file PATH|-): the run, request and one-time answer token default from LC_IE_RUN_ID, LC_IE_REQUEST_ID, LC_IE_ANSWER_TOKEN (flags --run-id, --request-id, --token override). SDK: Investigation.submit_agent_answer() (POST investigate/{oid}/runs/{run_id}/agent-answers/{request_id}, body {token, answer}, sent once, never retried).
  • The token is never shown. No positional argument for it; it is not printed, not in any error (the SDK's errors are built from the API's answer, and a refused input never repeats it), not in --help, and not in --debug / --debug-curl output: Client.request() gains redact_body, which replaces the request body in both debug paths. Tests cover the wire path (a real _rest_call with a captured log), the CLI and the SDK.
  • Refusals say what they mean (AGENT_ANSWER_MEANINGS, shown as the error's suggestion): 400 invalid_answer (every field and why, kept in the machine-readable document as fields; nothing was recorded, fix and resend before the deadline), 403 forbidden (wrong token; a 403 with no code is a missing investigation.get), 404 not_found, 409 already_answered / deadline_passed / not_waiting (too late), 501 not_implemented.
  • investigate runs start sends parent_run (from LC_IE_RUN_ID) when set, so a run an agent starts asks no further agent.
  • Checked the earlier queue commands against the engine's real answers: an empty queue has null for oldest_enqueued_at and hour.runs_per_hour, a person's start is a by_rule row with no rule key, hour.start_failed exists, and a repeated flush is answered with replayed: true. The commands already printed all of these; the one defect was queue flush saying "Flushed N" for a replayed answer, which flushed nothing itself. It now says so. Docs and docstrings describe the real shapes, and tests use the engine's documented answers (empty queue, person's start, replayed flush, flush still running) in json, table and yaml.

Docs: doc/cli/investigation-engine.md (new "AI agent answers" section, runs, queue), --explain text, investigation_engine discovery profile, CHANGELOG (Unreleased). No release, no publish.

Tests

pytest tests/unit/ tests/microbenchmarks/: 6754 passed (151 skipped, all pre-existing).

Self-review (adversarial)

  • Token leaks: checked --debug, --debug-curl, argv logging (cli.py reads sys.argv only for the --debug flag), error documents, --help with the variable set, invalid-id errors, usage errors for a missing value (name the variable, never a value).
  • A value in --token is the user's choice and stays in shell history: said in the help and the docs.
  • parent_run is read from the environment only; there is deliberately no flag to drop it.
  • Open (not changed here): a body bigger than 64 KiB is refused by the engine with invalid_answer; the CLI does not pre-check the size.

🤖 Generated with Claude Code

…layed flush

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@maximelb

Copy link
Copy Markdown
Contributor Author

/lc-review

@maximelb

Copy link
Copy Markdown
Contributor Author

Self-review (adversarial), as the author:

  • Token leaks: checked --debug, --debug-curl, argv logging (cli.py reads sys.argv only for the --debug flag), error documents, --help with the variable set, invalid-id errors, usage errors for a missing value (name the variable, never a value).
  • A value in --token is the user's choice and stays in shell history: said in the help and the docs.
  • parent_run is read from the environment only; there is deliberately no flag to drop it.
  • Open (not changed here): a body bigger than 64 KiB is refused by the engine with invalid_answer; the CLI does not pre-check the size.

lcbill
lcbill previously approved these changes Nov 27, 2026

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

Verdict: APPROVED (0 High, 0 Medium, 3 Low)

I found no High or Medium issues. Secret handling looks right. redact_body is passed from Investigation._call through Client.request and _rest_call to both debug paths. The token is sent only in the JSON body, never in the URL or query. The SDK and CLI errors are built from the API response, refused input, or variable names, never from the token value. test_debug_logging.TestRedactBody checks the real _rest_call debug output.

General Feedback

  • No test-time-budget check run was found for this commit. The base branch master does not require it (branch protection and rulesets list no such check), and this PR does not change any workflow.
  • Note (not counted): the PR body and docs say the answer is "sent once and never retried". In practice, Client.request can still send the same body again after a 401 (JWT refresh) or a 429 (when quota retries are on). The server refused both of those before recording anything, so the guarantee still holds for the engine. The wording is just slightly broader than the code.

Blast radius

  • Client.request / _rest_call / _debug_request / _debug_curl_cmd gain an optional redact_body keyword, default False. Existing callers are unaffected. Code that subclasses Client and overrides these methods with the old signature would get a TypeError when the new SDK call passes redact_body.
  • InvestigationError.to_dict() now adds fields whenever an engine error body has a non-empty fields dict. This applies to every investigate command's structured error output, not just answer.
  • investigate runs start now sends parent_run whenever LC_IE_RUN_ID is set in the environment. A script that inherits that variable will have its starts treated as agent-made (no AI agent steps). Direct SDK users of start_run do not get this guard.
  • investigate queue flush changes its stderr note for replayed: true answers. The stdout document is unchanged.

This review was generated automatically by Claude Code.

Comment thread limacharlie/commands/investigate.py Resolved
Comment thread tests/unit/test_cli_investigate.py Resolved
Comment thread limacharlie/sdk/investigation.py Resolved
…gs, full-path debug test)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@maximelb

Copy link
Copy Markdown
Contributor Author

/lc-review

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

Verdict: APPROVED (0 High, 0 Medium, 0 Low)

Re-review of the commits since dd187c8. Five files changed: the doc, commands/investigate.py, sdk/investigation.py and both test modules. The other files are unchanged since my last review. All three earlier Low findings are fixed (see the thread replies). The new code is correct: a blank --run-id/--request-id/--token is now refused, not replaced by the environment value. A 404 with no engine code now gets the route hint. The new SDK test runs a real Client with urlopen patched and all debug modes on, so it covers the whole redaction path.

General Feedback

  • Note (carried over, not counted): the submit_agent_answer docstring now says the call is replayed "only after a 401 token refresh". Client.request also resends the same body after a 429 when the client was built with is_retry_quota_errors=True. The server refused that request before it recorded anything, so the one-answer guarantee still holds. Only the wording is narrower than the code.
  • No test-time-budget check run was found for this commit. master does not require the check (branch protection and rulesets list none), and this PR does not change any workflow.

Blast radius

This is the same as the last review. Client.request/_rest_call/debug helpers gain an optional redact_body keyword (default False). InvestigationError.to_dict() adds fields for every investigate command. runs start sends parent_run whenever LC_IE_RUN_ID is set. The new answer command now refuses blank flag values with exit code 2.


This review was generated automatically by Claude Code.

lcbill
lcbill previously approved these changes Nov 27, 2026
…de-less 403

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@maximelb

Copy link
Copy Markdown
Contributor Author

/lc-review

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

Verdict: APPROVED (0 High, 0 Medium, 0 Low)

Re-review of the commits since 11f9da9. Only limacharlie/sdk/investigation.py and tests/unit/test_sdk_investigation.py changed. The other PR files are unchanged since my last review. My three earlier findings were already confirmed fixed in their threads.

The new code is correct:

  • submit_agent_answer now serializes the answer with allow_nan=False and refuses an answer that contains the token before any request is sent. The error message does not repeat the token. The test checks this through the real SDK method, and checks that client.request is never called.
  • The 403 message with no engine code now also mentions a missing key id. A new parametrized case covers it.

General Feedback

  • Note (carried over, not counted): the docstring says the call is replayed "only after a 401 token refresh". Client.request also resends after a 429 when is_retry_quota_errors=True. The server refused that request before recording anything, so only the wording is off.
  • Note (not counted): the token-in-answer check matches against json.dumps output, which uses ensure_ascii=True. A token with non-ASCII, " or \ characters would be escaped there and not match. Engine tokens are presumably URL-safe ASCII, so this does not matter in practice.
  • No test-time-budget check run was found for this commit. master does not require the check (branch protection and rulesets list none), and this PR does not change any workflow.

Blast radius

Same as the last review, plus one change. Client.request, _rest_call and the debug helpers gain an optional redact_body keyword (default False). InvestigationError.to_dict() adds fields for every investigate command. runs start sends parent_run whenever LC_IE_RUN_ID is set. New: Investigation.submit_agent_answer now raises ValidationError for answers that are not JSON-safe or that contain the token. This affects SDK callers as well as the CLI.


This review was generated automatically by Claude Code.

@maximelb

Copy link
Copy Markdown
Contributor Author

Review round 1 threads: the ambient LC_IE_RUN_ID is now cleared for every test in the module (autouse fixture); the vacuous debug test was dropped and replaced by a test through a real Client with every debug mode on; the wording no longer promises fields (the API does not relay them yet; the message names each field). Resolved. Approved 0/0/0 on this head; merging once CI is green.

@maximelb
maximelb merged commit 52226b1 into master Nov 27, 2026
7 checks passed
@maximelb
maximelb deleted the ia-ca-answer-cli branch November 27, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants