You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e3caccb
Browse filesBrowse the repository at this point in the historyBrowse files
Tell a Bot in its system prompt when one of its capabilities is down (#3274)
Fixes#3273
Written-by: FlyBot Dev-1
Owner: Dev-1
Reviewer: Reviewer
Tier: T2 (`core/src/host/**` is T2 in `.github/agent/risk-rules.json`;
the tests, the client dictionary, the doc and the fragment are T0/T1)
Claim-Id: 996fccbc55c04237b11177afbdbbca47
Base: 4a3ad73
## What changed
A Bot agreed to work it could not do: one of its attached MCP
capabilities had failed or was waiting for approval, and the only places
that knew were the client badge (`channel.js:223`) and
`list_capabilities`, a tool the Bot has to think to call. Nothing in the
system prompt said it.
`core/src/host/prompt.js` registers a second section beside
`bot-identity` — `bot-capabilities`, `order: 700`, `interpolate: false`
— for the rendering Session's own Bot. It reads
`capabilityStatusesView()[bot.id]`, keeps the capabilities in state
`error` or `needs-approval`, and renders one line each under a single
heading line:
```
# Capabilities that need attention
- github (mcp): 401 bad credentials — tell the user before acting.
```
The `<kind>` comes from `capabilityLibraryView()`. A capability in
`error` carries the reason the host already stores — redacted and cut to
300 characters by `capabilities.js` — with its whitespace collapsed so
one capability stays one line, and an empty or whitespace-only reason
reads `not connected` rather than leaving a dangling dash;
`needs-approval` renders `needs user approval`, the wording the
capability tools already use. The heading is the only text besides those
lines: a bare dash list would not say these are the Bot's own
capabilities.
The status view aggregates per Bot across its Sessions, so a failure
reached in one Session is the whole Bot's failure — the same rule
`list_capabilities` already follows — and one Bot never sees another's
state. Both are asserted.
When every attached capability is `ready`, or the Bot has none, the
section text is `''`. DSH drops empty sections and joins the rest with a
blank line (`dsh-system-prompt` `renderSections`), so the rendered
prompt is byte-identical to today's; the test now pins the rendered head
and last line as literals and proves the same bytes against the base
source (main 11445, worker 9059, relay 272, non-Bot 0 characters). The
identity section is untouched and its header comment states that
capability state stays out of it.
## From the security read at `6b401ebb`
One reachable path was not closed by the section itself.
`capabilities.js` accepted a URL such as
`https://alice:s3cr3t-pa55@host/mcp` (only the protocol was checked),
`configFor` passed it through raw, and when the mount failed the
transport error quoted it back verbatim — `redactSecrets` replaces saved
*key values*, not an inline credential — so the sentence that would now
be printed every turn carried the password. Two changes close it:
- the save refuses a URL carrying userinfo: `Enter the URL without a
username or password. Save the credential as a secret and reference it
in a header.` (seven fixed refusals on this form now; the Chinese text
is in `core/src/client/i18n.js` and `settings-error-placement.test.js`
holds the pair)
- a stored transport error of a capability saved before that refusal has
its userinfo masked before the 300-character cut, so an old item cannot
print it either
`prompt.js` is unchanged by this half: the string must not exist, not be
hidden at the sink.
Residual, weighed and not missed: a server can echo a literal header
value in its own error body (`Error POSTing to endpoint: …`). That class
is already reachable today through a connected server's instructions;
here it is bounded to 300 characters and one line, and it is not a shape
the host can recognise as a credential.
The client half is exactly that dictionary entry:
`core/src/client/i18n.js` gains the zh sentence, `core/client.js`
carries the same map (built with `npm run build`), and
`settings-error-placement.test.js` gains the pair. No client behaviour,
tool set, protocol or workflow changes, and no visual change — the
refusal draws in the form's existing alert row, which already shows six
other refusals — so there is no new screenshot and the prompt text stays
model-facing English like every other rule in that file.
Docs-not-needed: client.js and core/src/client/i18n.js changed only to
carry the zh dictionary entry for the new host refusal string from
#3273; no client behaviour, API or subsystem contract changed.
## Red first
The prompt section (first commit, test-only tree on base `4a3ad732`):
`node --test core/test/prompt.test.js` → `# tests 7 / # pass 3 / # fail
4`, the four new cases failing on `actual: false`, `undefined`,
`undefined` and `undefined !== ''`.
The security fix, on the same tree with source unfixed:
- `node --test core/test/capabilities.test.js` → `# tests 20 / # pass 18
/ # fail 2`
- `a capability URL that carries a username or password is refused, and
nothing is stored` → `Missing expected rejection.`
- `an error that quotes a URL saved before this fix stores it with the
userinfo masked` → actual `Request cannot be constructed from a URL that
includes credentials: https://alice:s3cr3t-pa55@host/mcp`, expected `…:
https://host/mcp`
- `node --test core/test/prompt.test.js` with the empty-reason case
added → `# tests 9 / # pass 8 / # fail 1`
- `an error with no reason still reads as a sentence` → the line
rendered `- github (mcp): — tell the user before acting.` (double space,
no reason)
Green after the fix, each file run twice in a row: `prompt.test.js` `#
tests 9 / # pass 9 / # fail 0`, `capabilities.test.js` `# tests 20 / #
pass 20 / # fail 0`.
## Verification at the tip
Tip SHA: `8d991600778474b887f01b2784b8c72327c8a109` (the author's
`c412b65bfa90a74220e0b83de2b55607d3260c7c` = tree `c7ed581f` plus one
docs-only commit from `Written-by: Rework` that adds the `core-client`
rule; 15 files, +544/−21, on base
`4a3ad73274111bba22e3e9628b7a9e5f5c7bc62b`). The readings below ran on
the author's tree; the docs commit changes no code.
Ran:
- `TZ=UTC npm run verify` → exit 0: core 3402/3402/0, plane 25/25/0,
social 758/758/0, tree 152/152/0, timeline 172/172/0, workflow
538/538/0, project 151/151/0, `.github/scripts`+`policy` 724/724/0,
interop 37/37/0, live-e2e 34/34/0
- in that run: `build-client.mjs --check` rc 0, `ds-bot-patches.mjs
check` three ok lines and `canonical` no-op, oxlint 0 errors (warnings
91 core, 40/9/2/16/0 across the plugins — all in files this branch does
not touch)
- `ARCH_DOCS_BASE=4a3ad73274111bba22e3e9628b7a9e5f5c7bc62b npm run
arch-docs` (in `core/`) → the local run reported OK, but CI at
`76856c3c` failed the same step: `core/client.js` and
`core/src/client/i18n.js` are owned by `core-client` and the branch did
not touch `docs/subsystems/core-client.md`. That page now carries the
rule (+1 line, no code), so the gate has its doc at this tip.
- `node scripts/ds-bot-patches.mjs generate` → rc 0, then `git status
--porcelain` 0 lines
- `node --test core/test/prompt.test.js` 9/9 twice,
`core/test/capabilities.test.js` 20/20 twice,
`core/test/settings-error-placement.test.js` 6/6,
`core/test/i18n.test.js` 5/5, `core/test/install.test.js` 6/6 (all
through `test/harness-resolve.mjs`, as `npm test` runs them)
- the base-against-tip render probe: `installBase` from `4a3ad732`'s
`prompt.js` and this tip's `install` produce identical text for main
(11445), worker (9059), relay (272) and a non-Bot (0), then the probe
files were deleted
- `node .github/scripts/changelog.mjs check` → `1 fragment(s) in
changelog.d/ are well formed`
- `node .github/scripts/check-mojibake.mjs --check` → 0 occurrences of
U+FFFD in 1771 text files
Not run:
- the `dev/bench.sh smoke` test (needs a DSH checkout and a free port);
`verify` is the gate that covers this change
- no screenshot: no visual state changes (the refusal uses the form's
existing alert row)
- the box's `TMPDIR` points at a read-only directory, so every command
ran with `env -u TMPDIR` (system `/tmp`) and a workspace
`npm_config_cache`; that is this machine, not the change
## Checkpoint
<!-- flybot:checkpoint -->
```json
{
"pr": 3274,
"claim": "Dev-1",
"issue": 3273,
"summary": "#3273: a Bot now sees its own broken capability in the system prompt, one line each for error and needs-approval, and an empty section while every capability is ready. From the security read at 6b401eb the same pass refuses a capability URL carrying userinfo and masks a stored transport error's userinfo, so a credential cannot reach that line. Tests cover the failed connection, the unapproved capability, the mixed case, one Bot's isolation from another, an empty reason, the refused save, the masked stored error, a plain URL, and the byte-identical healthy render.",
"files": [
"core/src/host/prompt.js",
"core/src/host/capabilities.js",
"core/src/client/i18n.js",
"core/client.js",
"core/test/prompt.test.js",
"core/test/capabilities.test.js",
"core/test/settings-error-placement.test.js",
"core/test/install.test.js",
"changelog.d/3273.fixed.md",
"docs/subsystems/core-host.md",
"patches/ds-bot/0001-core-fixes.patch",
"patches/ds-bot/0008-client-bundle.patch"
],
"checks": {
"ran": "TZ=UTC npm run verify; prompt.test.js 9/9 ×2; capabilities.test.js 20/20 ×2; ds-bot-patches generate + check + canonical; ARCH_DOCS_BASE=4a3ad7327411 arch-docs; changelog check",
"result": "green",
"at": "8d991600778474b887f01b2784b8c72327c8a109"
},
"next": "none — ready for review"
}
```
<!-- /flybot:checkpoint -->
---------
Co-authored-by: Danyang Chen <birfychen@gmail.com>
A Bot now learns from its system prompt that one of its own capabilities cannot be used right now, naming the capability and the reason, so it says "GitHub isn't connected (401 bad credentials)" before acting instead of agreeing to the work and failing half a turn later ([#3273](https://github.com/ThinkFlowLab/FlyBot/issues/3273)). Saving a capability URL that carries a username or password is refused, and an older error that quotes such a URL is stored with the userinfo masked, so a credential can never be printed into the Bot's system prompt ([#3273](https://github.com/ThinkFlowLab/FlyBot/issues/3273)).
Copy file name to clipboardExpand all lines: core/client.js
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1912,6 +1912,9 @@ var HOST_ZH = {
1912
1912
'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': "能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。",
1913
1913
"Enter a command for the MCP server.": "请填写 MCP 服务器的命令。",
1914
1914
"Enter a valid HTTP or HTTPS URL.": "请填写有效的 HTTP 或 HTTPS 地址。",
1915
+
// #3273: a URL carrying userinfo is refused instead of stored, so the credential never reaches
1916
+
// a status line and never reaches the system prompt.
1917
+
"Enter the URL without a username or password. Save the credential as a secret and reference it in a header.": "地址里不要写用户名或密码。请把凭据保存为密钥,并在请求头里引用它。",
1915
1918
"A capability cannot change its kind. Delete it and save a new one.": "能力类型不能改。请删掉它,再新建一个。",
1916
1919
"Environment variables must contain text values.": "环境变量里只能填文本值。",
1917
1920
"Headers must contain text values.": "请求头里只能填文本值。"
Copy file name to clipboardExpand all lines: core/src/client/i18n.js
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1872,6 +1872,9 @@ const HOST_ZH = {
1872
1872
'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': '能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。',
1873
1873
'Enter a command for the MCP server.': '请填写 MCP 服务器的命令。',
1874
1874
'Enter a valid HTTP or HTTPS URL.': '请填写有效的 HTTP 或 HTTPS 地址。',
1875
+
// #3273: a URL carrying userinfo is refused instead of stored, so the credential never reaches
1876
+
// a status line and never reaches the system prompt.
1877
+
'Enter the URL without a username or password. Save the credential as a secret and reference it in a header.': '地址里不要写用户名或密码。请把凭据保存为密钥,并在请求头里引用它。',
1875
1878
'A capability cannot change its kind. Delete it and save a new one.': '能力类型不能改。请删掉它,再新建一个。',
1876
1879
'Environment variables must contain text values.': '环境变量里只能填文本值。',
1877
1880
'Headers must contain text values.': '请求头里只能填文本值。',
}catch{thrownewError('Enter a valid HTTP or HTTPS URL.')}
120
+
letparsed
121
+
try{parsed=newURL(url)}catch{thrownewError('Enter a valid HTTP or HTTPS URL.')}
122
+
if(parsed.protocol!=='https:'&&parsed.protocol!=='http:')thrownewError('Enter a valid HTTP or HTTPS URL.')
123
+
if(parsed.username!==''||parsed.password!=='')thrownewError('Enter the URL without a username or password. Save the credential as a secret and reference it in a header.')
assert.equal(status.error,'Request cannot be constructed from a URL that includes credentials: https://host/mcp','the exact stored sentence: the scheme and host stay, the userinfo is gone')
statuses: {worker: {github: {state: 'error',error: '401 bad credentials'}}},
100
+
library: [{name: 'github',kind: 'mcp'}],
101
+
})
102
+
t.after(()=>ctx.dispose())
103
+
consttext=render('worker')
104
+
assert.equal(capabilities('worker').split('\n')[0],'# Capabilities that need attention','the section carries its own title, so the list is not read as a continuation of the identity block')
105
+
assert.equal(capabilities('worker').split('# Capabilities that need attention').length-1,1,'one title, once')
106
+
assert.ok(
107
+
text.split('\n').includes('- github (mcp): 401 bad credentials — tell the user before acting.'),
108
+
`the failed capability and its reason are on one line:\n${text}`,
109
+
)
110
+
assert.equal(text.slice(0,prompt('worker').length),prompt('worker'),'the identity section is untouched')
'- github (mcp): 401 bad credentials — tell the user before acting.',
142
+
'- slack (pack): needs user approval — tell the user before acting.',
143
+
])
144
+
})
145
+
146
+
// Test found by mutation that a healthy render compared only against another render of the same
147
+
// code proves nothing: a trailing space added to the identity text passes both sides. The claim is
148
+
// that the healthy prompt *is* the identity text, so its exact head and its exact last line are
149
+
// pinned here as literals, and the capability section has to contribute the empty string.
150
+
constIDENTITY_LAST_RULE='- When you cannot continue without an answer, pass ask with the one question on that task. On a group card, worked in your own chat, call ask_user for the user, and post one short question in the group only when a person there has to decide. On your own chat\'s other tasks, ask_user. When the answer arrives, pass answer with what they said and update the task. Do not leave the task waiting without that question.'
151
+
constIDENTITY_HEADS={
152
+
main: "# Your identity\nYou are Chief, a Bot on the user's team in FlyBot.",
153
+
worker: "# Your identity\nYou are Dev, a Bot on the user's team in FlyBot.",
154
+
}
155
+
156
+
test('#3273: a healthy Bot renders exactly the prompt it renders today',(t)=>{
assert.equal(healthy.capabilities(id),'','nothing unhealthy renders no section text at all')
166
+
consttext=healthy.render(id)
167
+
assert.ok(text.startsWith(IDENTITY_HEADS[id]),`${id}: the rendered prompt starts on the identity title and the Bot's own line, byte for byte`)
168
+
assert.ok(text.endsWith(IDENTITY_LAST_RULE),`${id}: the rendered prompt ends on the last identity rule — no separator, no blank line, no trailing space`)
169
+
assert.equal(text.trimEnd(),text,`${id}: no trailing whitespace`)
170
+
assert.equal(healthy.render(id),none.render(id),'byte for byte the prompt a Bot with no capabilities gets')
171
+
assert.equal(none.render(id),none.prompt(id),'the rendered prompt is the identity section alone — no extra section, no blank line')
172
+
}
173
+
// A relay session is not a Bot: it never carries capability state.
0 commit comments